﻿using System;
using System.IO;
using System.Text;
using Terraria.Chat.Commands;

namespace Terraria.Chat
{
	// Token: 0x02000491 RID: 1169
	public class ChatMessage
	{
		// Token: 0x170002C8 RID: 712
		// (get) Token: 0x0600275D RID: 10077 RVA: 0x0001B885 File Offset: 0x00019A85
		// (set) Token: 0x0600275E RID: 10078 RVA: 0x0001B88D File Offset: 0x00019A8D
		public ChatCommandId CommandId { get; private set; }

		// Token: 0x170002C9 RID: 713
		// (get) Token: 0x0600275F RID: 10079 RVA: 0x0001B896 File Offset: 0x00019A96
		// (set) Token: 0x06002760 RID: 10080 RVA: 0x0001B89E File Offset: 0x00019A9E
		public string Text { get; set; }

		// Token: 0x06002761 RID: 10081 RVA: 0x0001B8A7 File Offset: 0x00019AA7
		public ChatMessage(string message)
		{
			this.CommandId = ChatCommandId.FromType<SayChatCommand>();
			this.Text = message;
		}

		// Token: 0x06002762 RID: 10082 RVA: 0x0001B8C1 File Offset: 0x00019AC1
		private ChatMessage(string message, ChatCommandId commandId)
		{
			this.CommandId = commandId;
			this.Text = message;
		}

		// Token: 0x06002763 RID: 10083 RVA: 0x00494988 File Offset: 0x00492B88
		public void Serialize(BinaryWriter writer)
		{
			this.CommandId.Serialize(writer);
			writer.Write(this.Text);
		}

		// Token: 0x06002764 RID: 10084 RVA: 0x004949B0 File Offset: 0x00492BB0
		public int GetMaxSerializedSize()
		{
			int num = 0;
			num += this.CommandId.GetMaxSerializedSize();
			return num + (4 + Encoding.UTF8.GetByteCount(this.Text));
		}

		// Token: 0x06002765 RID: 10085 RVA: 0x004949E4 File Offset: 0x00492BE4
		public static ChatMessage Deserialize(BinaryReader reader)
		{
			ChatCommandId commandId = ChatCommandId.Deserialize(reader);
			string message = reader.ReadString();
			return new ChatMessage(message, commandId);
		}

		// Token: 0x06002766 RID: 10086 RVA: 0x0001B8D7 File Offset: 0x00019AD7
		public void SetCommand(ChatCommandId commandId)
		{
			this.CommandId = commandId;
		}

		// Token: 0x06002767 RID: 10087 RVA: 0x0001B8E0 File Offset: 0x00019AE0
		public void SetCommand<T>() where T : IChatCommand
		{
			this.CommandId = ChatCommandId.FromType<T>();
		}
	}
}
